// class Container{
//     constructor(value){
//         this.value = value
//     }

//     map(fn){
//         return new Container(fn(this.value))
//     }

// }

// let container = new Container(5).map(value=>value+1)
// console.log(container)

class MayBe{
    constructor(value){
        this._value = value
    }
    static of(value){
        return new  MayBe(value)
    }

    //判断是否为null
    map(fn){
        console.log(this._value)
        return  this.isNothing()? MayBe.of(null):new MayBe(fn(this._value))
    }

    isNothing(){
        return this._value === null || this._value === undefined
    }
}

let result = MayBe.of("qq").map(item=>item.toUpperCase()).map(item=>null).map(item=>item+1)
console.log(result) // MayBe { _value: null }



